package com.topisv.tms.rest;

import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.topisv.tms.rest.vo.AreaGroupProVo;
import com.topisv.tms.rest.vo.CustomerAreaGroupVo;
import com.topisv.tms.service.CustomerAreaGroupService;

import net.sf.json.JSONObject;

@Controller
@RequestMapping(value = "/api")
public class CustomerAreaGroup {
	private static final Logger log = LoggerFactory.getLogger(CustomerAreaGroup.class);
	
	@Autowired
	private CustomerAreaGroupService customerAreaGroupService;
	@RequestMapping(value = "ajaxUpdateCustomerAreaGroup", method = RequestMethod.POST)
	public void ajaxUpdateCustomerAreaGroup(@RequestParam(value = "json") String message,
			HttpServletRequest request, HttpServletResponse response) {
		PrintWriter out = null;
		JSONObject json = null;
		Map<String, Class> maps = null;
		try {
			out = response.getWriter();
			json = new JSONObject();
			log.info("ajaxUpdateCustomerAreaGroup==" + message);
			maps = new HashMap<String, Class>();
			maps.put("areaGroupProVos", AreaGroupProVo.class);
			CustomerAreaGroupVo customerAreaGroupVo=(CustomerAreaGroupVo)JSONObject.toBean(JSONObject.fromObject(message), CustomerAreaGroupVo.class, maps);
			customerAreaGroupService.save(customerAreaGroupVo);
			json.put("status", "1");
			json.put("content", "接收成功");
			log.info("ajaxUpdateCustomerAreaGroup==" + json.toString());
			out.print(json.toString());
		} catch (Exception e) {
			json.put("status", "0");
			json.put("content", e.getMessage());
			log.info("ajaxUpdateCustomerAreaGroup==" + json.toString());
			log.error("ajaxUpdateCustomerAreaGroupException==" + e);
			out.print(json.toString());
		}

	}

}
